// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#include "tests/util/test_common.h"

namespace nebula {

TestInt::TestInt() : value(-999) {}
TestInt::TestInt(int i) : value(i) {}  // NOLINT runtime/explicit
bool TestInt::operator==(const TestInt& other) const { return value == other.value; }

std::ostream& operator<<(std::ostream& os, const TestInt& v) {
  os << "{" << v.value << "}";
  return os;
}

TestStr::TestStr() : value("") {}
TestStr::TestStr(const std::string& s) : value(s) {}  // NOLINT runtime/explicit
TestStr::TestStr(const char* s) : value(s) {}         // NOLINT runtime/explicit
TestStr::TestStr(const TestInt& test_int) {
  if (turbo::is_iteration_end(test_int)) {
    value = "";
  } else {
    value = std::to_string(test_int.value);
  }
}

bool TestStr::operator==(const TestStr& other) const { return value == other.value; }

std::ostream& operator<<(std::ostream& os, const TestStr& v) {
  os << "{\"" << v.value << "\"}";
  return os;
}

std::vector<TestInt> RangeVector(unsigned int max, unsigned int step) {
  auto count = max / step;
  std::vector<TestInt> range(count);
  for (unsigned int i = 0; i < count; i++) {
    range[i] = i * step;
  }
  return range;
}

turbo::Transformer<TestInt, TestStr> MakeFilter(std::function<bool(TestInt&)> filter) {
  return [filter](TestInt next) -> turbo::Result<turbo::TransformFlow<TestStr>> {
    if (filter(next)) {
      return turbo::TransformYield(TestStr(next));
    } else {
      return turbo::TransformSkip();
    }
  };
}

}  // namespace nebula
